package java编程思想.第18章._10_nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class ChannelCopy {
	private static final int BSIZE = 10;

	public static void main(String[] args) throws IOException {
		FileChannel in = new FileInputStream("D://data.txt").getChannel(),
				out = new FileOutputStream("D://data1.txt").getChannel();
		ByteBuffer buffer = ByteBuffer.allocate(BSIZE);
		while (in.read(buffer) != -1) {
			buffer.flip();
			out.write(buffer);

			System.out.println(buffer.limit());
			buffer.clear();
			// buffer.rewind();
			System.out.println(buffer.limit());
		}
	}
}
